package com.lianbang.staff.module.main

import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import cn.ubest.mvvmcore.base.BaseFragment
import cn.ubest.mvvmcore.base.BaseListFragment
import cn.ubest.mvvmcore.databinding.IncludeListWithRefreshBinding
import cn.ubest.mvvmcore.utils.SpanUtils
import cn.ubest.mvvmcore.widget.ListDivider
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemClickListener
import com.chad.library.adapter.base.listener.OnLoadMoreListener
import com.google.android.material.tabs.TabLayout
import com.lianbang.staff.R
import com.lianbang.staff.adapter.OrderAddListAdapter
import com.lianbang.staff.adapter.ShopListAdapter
import com.lianbang.staff.bean.OrderListBean
import com.lianbang.staff.databinding.FragmentOrderBinding
import com.lianbang.staff.vm.MainVM
import com.lianbang.staff.vm.OrderVM
import com.scwang.smart.refresh.layout.api.RefreshLayout
import com.scwang.smart.refresh.layout.listener.OnRefreshListener
import kotlinx.android.synthetic.main.fragment_home.*
import kotlinx.android.synthetic.main.fragment_home.view.*
import kotlinx.android.synthetic.main.fragment_order.*

/**
 * Created by maoqi on 2020/12/28.
 */
class OrderChildListFragment :
    BaseListFragment<OrderVM, IncludeListWithRefreshBinding, OrderListBean>()
    , OnLoadMoreListener, OnRefreshListener, OnItemClickListener {

    private val mState by lazy {
        arguments?.getInt("state") ?: 0
    }

    companion object {
        fun newInstance(state: Int): OrderChildListFragment {
            val fragment = OrderChildListFragment()
            val bundle = Bundle()
            bundle.putInt("state", state)
            fragment.arguments = bundle
            return fragment
        }
    }

    override fun initLayout(): Int {
        return R.layout.include_list_with_refresh
    }

    override fun initData(arguments: Bundle?) {
        super.initData(arguments)
    }

    override fun initView(view: View) {
        super.initView(view)
        mRvList?.addItemDecoration(
            ListDivider.Build()
                .setColor(R.color.C_F3F5F9)
                .setMarginLeft(R.dimen.dp_20)
                .setMarinRight(R.dimen.dp_20)
                .build()
        )
    }

    override fun loadData() {
        mViewModel.refreshData(mState)
    }

    override fun initAdapter(): BaseQuickAdapter<OrderListBean, *> {
        return OrderAddListAdapter()
    }

    override fun onLoadMore() {
        mViewModel.loadData(mState)
    }

    override fun onRefresh(refreshLayout: RefreshLayout) {
        loadData()
    }

    override fun onItemClick(adapter: BaseQuickAdapter<*, *>, view: View, position: Int) {
    }

}